package com.zhuwhao.sample;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.jzxiang.pickerview.data.Type;
import com.zhuwhao.sample.utils.DateTimePickerUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DateTimePickerActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @BindView(R.id.btnAll)
    Button btnAll; //年月日时分

    @BindView(R.id.btnYearMonthDay)
    Button btnYearMonthDay; //年月日

    @BindView(R.id.btnHourMin)
    Button btnHourMin; //时分

    @BindView(R.id.btnMonthDayHourMin)
    Button btnMonthDayHourMin; //月日时分

    @BindView(R.id.btnYearMonth)
    Button btnYearMonth; //年月

    @BindView(R.id.btnYear)
    Button btnYear; //年

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_date_time_picker);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        toolbar.setTitle(R.string.date_time_picker);
        setSupportActionBar(toolbar);
    }

    @OnClick({R.id.btnAll, R.id.btnYearMonthDay, R.id.btnHourMin, R.id.btnMonthDayHourMin, R.id.btnYearMonth, R.id.btnYear})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnAll:
                new DateTimePickerUtils(this, btnAll.getText().toString(), Type.ALL, new DateTimePickerUtils.OnDateTimeSelectListener() {
                    @Override
                    public void onSelect(String dateTime) {
                        btnAll.setText(dateTime);
                    }
                }).show(getSupportFragmentManager());
                break;
            case R.id.btnYearMonthDay:
                new DateTimePickerUtils(this, btnYearMonthDay.getText().toString(), Type.YEAR_MONTH_DAY, new DateTimePickerUtils.OnDateTimeSelectListener() {
                    @Override
                    public void onSelect(String dateTime) {
                        btnYearMonthDay.setText(dateTime);
                    }
                }).show(getSupportFragmentManager());
                break;
            case R.id.btnHourMin:
                new DateTimePickerUtils(this, btnHourMin.getText().toString(), Type.HOURS_MINS, new DateTimePickerUtils.OnDateTimeSelectListener() {
                    @Override
                    public void onSelect(String dateTime) {
                        btnHourMin.setText(dateTime);
                    }
                }).show(getSupportFragmentManager());
                break;
            case R.id.btnMonthDayHourMin:
                new DateTimePickerUtils(this, btnMonthDayHourMin.getText().toString(), Type.MONTH_DAY_HOUR_MIN, new DateTimePickerUtils.OnDateTimeSelectListener() {
                    @Override
                    public void onSelect(String dateTime) {
                        btnMonthDayHourMin.setText(dateTime);
                    }
                }).show(getSupportFragmentManager());
                break;
            case R.id.btnYearMonth:
                new DateTimePickerUtils(this, btnYearMonth.getText().toString(), Type.YEAR_MONTH, new DateTimePickerUtils.OnDateTimeSelectListener() {
                    @Override
                    public void onSelect(String dateTime) {
                        btnYearMonth.setText(dateTime);
                    }
                }).show(getSupportFragmentManager());
                break;
            case R.id.btnYear:
                new DateTimePickerUtils(this, btnYear.getText().toString(), Type.YEAR, new DateTimePickerUtils.OnDateTimeSelectListener() {
                    @Override
                    public void onSelect(String dateTime) {
                        btnYear.setText(dateTime);
                    }
                }).show(getSupportFragmentManager());
                break;
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            onBackPressed();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}